package com.leagueoflegends.controller;

import com.github.pagehelper.PageInfo;
import com.leagueoflegends.bean.ChampionPassive;
import com.leagueoflegends.bean.ChampionPassiveDTO;
import com.leagueoflegends.bean.ChampionPassiveVO;
import com.leagueoflegends.service.ChampionPassiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/passive")
public class ChampionPassiveController {

    @Autowired
    ChampionPassiveService championPassiveService;

    @GetMapping
    public PageInfo<ChampionPassiveVO> pageList(
            @RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") int pageSize
    ) {
        List<ChampionPassiveVO> list = championPassiveService.selectAll(pageNum, pageSize);
        return PageInfo.of(list);
    }

    @PostMapping
    public String insert(@RequestBody ChampionPassive passive) {
        championPassiveService.insert(passive);
        championPassiveService.set1(passive.getChampionId());
        return "200";
    }

    @DeleteMapping("/{championId}")
    public String delete(@PathVariable Integer championId) {
        championPassiveService.delete(championId);
        championPassiveService.set0(championId);
        return "200";
    }

    @PutMapping
    public String update(@RequestBody ChampionPassive passive) {
        championPassiveService.update(passive);
        return "200";
    }

    @GetMapping("/selectOne")
    public ChampionPassive selectOne(Integer championId) {
        return championPassiveService.select(championId);
    }

    @RequestMapping("/allPassiveVO")
    public List<ChampionPassiveVO> allPassiveVO() {
        return championPassiveService.selectAllVO();
    }

    @RequestMapping("/countChampionHavePassive")
    public Integer countChampionHavePassive() {
        return championPassiveService.countChampionHavePassive();
    }

    @RequestMapping("/countAllChampion")
    public Integer countAllChampion() {
        return championPassiveService.countAllChampion();
    }

    @GetMapping("/searchChampionId/{title}")
    public Integer searchChampionId(@PathVariable String title) {
        return championPassiveService.searchChampionId(title);
    }

    @GetMapping("/searchNoPassiveChampion")
    public List<ChampionPassiveDTO> searchNoPassiveChampion() {
        return championPassiveService.searchNoPassiveChampion();
    }

    @GetMapping("/titleToPassive/{title}")
    public Integer titleToPassive(@PathVariable String title) {
        return championPassiveService.titleToPassive(title);
    }

    @GetMapping("/idToTitle/{id}")
    public List<String> idToTitle(@PathVariable int id) {
        return championPassiveService.idToTitle(id);
    }

    @PutMapping("/set0/{title}")
    public String set0(@PathVariable String title) {
        return "set0";
    }

    @PutMapping("/set1/{title}")
    public String set1(@PathVariable String title) {
        return "set1";
    }
}
